home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
- Subject: Re: Access carry flag from C
- Date: 19 Feb 96 21:38:03 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.824765883@rscernix>
- References: <Dn1C9z.DGv.0.net@indra.com>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <Dn1C9z.DGv.0.net@indra.com> sullivan@indra.com (Steve Sullivan) writes:
-
- >Is it possible to determine if a fixed point overflow has
- >occurred from within C? For example:
- > i = j + k;
- > if (overflowed) ....;
-
- In C, signed integer arithmetic overflow causes undefined behaviour.
- If a method for detecting the overflow exists, it is inherently
- platform specific.
-
- Unsigned arithmetic is performed modulo the number that is
- one greater than the largest value that can be represented by the
- resulting unsigned integer type, so you can detect the "overflow",
- by using various arithmetic tricks. In the particular case of addition,
- if the result is not greater than both operands, the result "wrapped
- around".
-
- There is no carry flag in C and the language doesn't provide direct
- access to the underlying hardware features.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-